package org.brisling.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	private DateUtil(){};	
	
	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	public static String date2JsonStr(Date date){
		
		String retDate = null;
		
		if(date!=null){
			try{
				retDate = sdf.format(date);
			}catch(Exception e){
				e.printStackTrace();				
			}
		}
		return retDate;
	}
	
	public static Date JsonStr2Date(String _date){
		Date retDate = null;
		Integer _dateLength = _date.length();
		
		switch(_dateLength){
			case 10
				:_date += " 00:00:00";
				break;
			case 13
				:_date += ":00:00";
				break;
			case 16
				:_date += ":00";
				break;
		}
		try{
			retDate = sdf.parse(_date);
		}catch(Exception e){
			e.printStackTrace();
		}
		return retDate;
	}
}
